package cn.stylefeng.guns.base;

import cn.stylefeng.guns.GunsApplication;
import cn.stylefeng.guns.sys.core.util.DateUtil;
import cn.stylefeng.guns.sys.modular.system.model.params.DsstoreBillParam;
import cn.stylefeng.guns.sys.modular.system.service.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import java.util.List;


/**
 * 基础测试类
 *
 * @author stylefeng
 * @Date 2017/5/21 16:10
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = GunsApplication.class)
@WebAppConfiguration
//@Transactional //打开的话测试之后数据可自动回滚
public class BaseJunit {
    private Logger logger = LoggerFactory.getLogger(BaseJunit.class);
    @Autowired
    WebApplicationContext webApplicationContext;

    @Autowired
    private BtyInventoryService btyInventoryService;

    @Autowired
    private CompanyInfoService companyInfoService;


    @Autowired
    private AreaService areaService;

    @Autowired
    private ItemTypeService itemTypeService;

    @Autowired
    private ItemInterfaceService itemInterfaceService;

    @Autowired
    private DsstoreBillService dsstoreBillService;

    @Autowired
    private BtyShopTreeService btyShopTreeService;

    @Autowired
    private BtyShopService btyShopService;

    @Autowired
    private ItemUnitService itemUnitService;

    protected MockMvc mockMvc;

    @Before
    public void setupMockMvc() {
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
    }

    @Before
    public void initDatabase() {
    }


    /**
     * 库存流水记录数据录入测试
     *
     * @author jiangge
     * @date 2020/9/7 16:35
     */
    @Test
    public void getDsstorebillAndInsert() {
        //

        List<String> betweenDate = DateUtil.getBetweenDate("2020-09-01", "2020-09-02");

        for (String day : betweenDate) {
            logger.info("库存流水集市定时任务-开始执行数据写入,日期：{}", day);
            Integer dataCount = btyInventoryService.getDsstorebillAndInsert(day);
            logger.info("库存流水集市定时任务-结束执行数据写入,日期：{},写入库数量：{}", day, dataCount);
        }

    }

    /**
     * 初始化区域树父级
     */
    @Test
    public void initAreaPids() {
        //areaService.initAreaPids();
    }

    /**
     * 初始化品类数据
     */
    @Test
    public void initItemTypeData() {
        itemTypeService.initItemTypeData();
    }

    /**
     * 初始化品项数据
     */
    @Test
    public void initIntemInferfaceData() {
        itemInterfaceService.initIntemInferfaceData();
    }


    /**
     * 门店库存流水集市数据导入测试
     */
    @Test
    public void initDsstorebillData() {

        List<String> betweenDate = DateUtil.getBetweenDate("2020-09-15", "2020-09-16");

        for (String day : betweenDate) {
            logger.info("门店库存流水定时任务-开始执行数据写入,日期：{}", day);
            Integer dataCount = dsstoreBillService.initDsstorebillData(day);
            logger.info("门店库存流水定时任务-结束执行数据写入,日期：{},写入库数量：{}", day, dataCount);
        }
    }


    /**
     * 拉取数据-门店数据
     */
    @Test
    public void initShopData() {
        logger.info("门店数据入库-开始执行");
        btyShopService.initShopData();
        logger.info("门店数据入库结束-结束执行");
    }

    /**
     * 拉取数据-分公司档案数据
     */
    @Test
    public void initCompanyInfoData() {
        logger.info("分公司档案数据入库-开始执行");
        companyInfoService.initCompanyInfoData();
        logger.info("分公司档案数据入库-结束执行");
    }

    /**
     * 初始化门店树数据ShopTeeData
     */
    @Test
    public void initShopTeeData() {
        btyShopTreeService.initShopTeeData();
    }

    /**
     *
     */
    @Test
    public void initItemUnitData() {
        logger.info("初始化品项单位数据-开始执行");
        itemUnitService.initItemUnitData();
        logger.info("初始化品项单位数据-结束执行");
    }


    /**
     * 为shopTree赋值shopCode
     */
    @Test
    public void setShopCodes() {
        btyShopTreeService.setShopCodes();
    }


    /**
     * 测试库存获取 本期结存数据 结果
     */
    @Test
    public void getConutDataResult() {
        DsstoreBillParam param = new DsstoreBillParam();
        param.setShopCode("023");
        param.setItemTypeCode("101");
        param.setStartTime("2020-09-01");
        param.setStartTime("2020-09-16");
        dsstoreBillService.getConutDataResult(param);
    }

}
